import tkinter as tk;
import keyboard,time,threading;
import pyautogui,sys,ctypes;
pyautogui.PAUSE = 0;
def is_admin():
    try:
        return ctypes.windll.shell32.IsUserAnAdmin();
    except:
        return False;
if is_admin():
    pass;
else:
    ctypes.windll.shell32.ShellExecuteW(None,"runas", sys.executable, __file__, None, 1);
    sys.exit();
entered = False;
value = 0;
def val(number):
    global value;
    value = number;
def err_show(message,geonetry="240x20",width_=30,height_=1,title="错误"):
    err_window = tk.Tk();
    err_window.title(title);
    err_window.geometry(geonetry);
    err_lb = tk.Label(err_window,text=message,width=width_,height=height_,fg="black");
    err_lb.pack();
    err_window.mainloop();
def start_():
    while keyboard.is_pressed('ctrl+t') == False:
        if text_1.get() == "左":
            pyautogui.click();
            time.sleep(sleep);
        else:
            pyautogui.rightClick();
            time.sleep(sleep);
def start():
    global sleep;
    while True:
        while keyboard.is_pressed('ctrl+k')==False:
            pass;
        sleep = 1/inpu;
        start_();
def get():
    global inpu;
    global entered;
    try:
        inpu=int(text.get());
    except:
        err_show("你输入的数值不符合要求，请重新输入");
        return None;
    if text_1.get() != "左" and text_1.get() != "右":
        err_show("你输入的数值不符合要求，请重新输入");
        return None;
    if inpu <= 1000 == False or inpu >=1 == False:
        err_show("你输入的数值不符合要求，请重新输入");
    elif entered:
        err_show("你已经输入过，重新输入需重新打开程序","260x20",30);
    else:
        entered = True;
        massage = "你填写的数："+str(inpu)+"   按下 contral+k 开始\n按下 contral+t 停止,重新输入得重开程序";
        lb_2 = tk.Label(window,text=massage,width=32,height=4,fg="black");
        lb_2.pack();
        thread = threading.Thread(target=start);
        thread.start();
window = tk.Tk();
window.title("连点器");
window.geometry("230x190");
lb = tk.Label(window,text="每秒点击次数(在1-1000内)",width=20,height=1,fg="black");
lb_1 = tk.Label(window,text="点击左右键，输入左/右",width=20,height=1,fg="black");
text = tk.Entry(window,width=4);
bt = tk.Button(text="输入好了",width=7,command=get,fg="black");
text_1 = tk.Entry(window,width=2);
lb_3 = tk.Label(window,text="鼠标连点器V1.0.0   2023.10.13",width=24,height=2,fg="black");
lb.pack();
text.pack();
lb_1.pack();
bt.pack();
text_1.pack();
lb_3.pack();
tk.mainloop();
